home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / cenvid / mandlbrt.cmm < prev    next >
Encoding:
Text File  |  1995-10-05  |  1.0 KB  |  51 lines

  1. // Mandlbrt.cmm - Demonstrate Graphics.lib by drawing the
  2. // ver.1          familiar mandlebrot fractal.  This is
  3. //                and example of GRAPHICS.LIB
  4.  
  5. #include <graphics.lib>
  6.  
  7. if( !defined(_DOS_) )
  8. {
  9.   printf("This program will only run under the DOS %sversion of CEnvi.\n",
  10.          defined(_DOS32_)?"(not DOS 32 bit) ":"");
  11.   exit(EXIT_FAILURE);
  12. }
  13.  
  14. #define ITERATIONS   32
  15.  
  16. StartVGA();
  17.  
  18. // pick cool red, green, and blue colors for the palette
  19. for ( loop = 0; loop < 64; loop++ ) {
  20.     setpalette(64-loop, loop, loop * 2, loop * 3);
  21. }
  22.  
  23. for ( i = 0; i < 100; i ++) {
  24.     i2 = (i-100) * 3.0 / 200;
  25.     for (r = 0; r < 320; r++) {
  26.         iter = ITERATIONS;
  27.         putpixel(r,i,1);
  28.         putpixel(r,199-i,1);
  29.         r2 = (r-200)*3.3 /320;
  30.         x = 0.; y = 0.;
  31.         do {
  32.             iter --;
  33.             xn = x*x - y*y;
  34.             yn = 2*x*y;
  35.             x = xn+r2;
  36.             y = yn+i2;
  37.         } while (iter > 0 ) && x*x+y*y < 4;
  38.         putpixel(r,i,iter * 2);
  39.         putpixel(r,199-i,iter * 2);
  40.  
  41.         if kbhit() {
  42.          CloseVGA();
  43.          exit(1);
  44.       }
  45.     }
  46. }
  47. getch();
  48.  
  49.  
  50. CloseVGA();
  51.